package com.example.demo.producer;

import com.example.demo.store.Store;

/**
 * @author: wukangrong
 * @date: 2020/4/22 13:53
 * @description:
 */
public class Producer implements Runnable  {

//    public Producer(String name) {
//        this.setName(name);
//    }

    @Override
    public void run() {
        while (true) {
//            Store.lock.lock();
//            try {
//                if (Store.list.size() == Store.MAX) {
//                    System.out.println("仓库爆满..");
//                    Store.pro.await();
//                }
//
//                Store.list.add(1);
//                Store.con.signal();
//                System.out.println("生产者生产...仓库剩余：" + Store.list.size());
//                Thread.sleep(500);
//            } catch (Exception e) {
//            } finally {
//                Store.lock.unlock();
//            }
//            try {
//                Store.semaphore.acquire();
//                if (Store.MAX == Store.list.size()) {
//                    System.out.println("仓库爆满！");
//                    Store.semaphore.release();
//                    Thread.sleep(1000);
//                    continue;
//                }
//                Store.list.add(1);
//                Store.semaphore.release();
//                System.out.println("生产者生产...仓库剩余：" + Store.list.size());
//                Thread.sleep(300);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
            Store.operation(Store.PRODUCE);
            try {
                Thread.sleep(450);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
